home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / dev / misc / WHDLoad_dev.lha / WHDLoad / Src / sources / whdload / keyboard.s < prev    next >
Encoding:
Text File  |  1999-10-08  |  3.2 KB  |  129 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    keyboard.s
  3. ;  :Contents.    routine to setup an keyboard handler
  4. ;  :Version.    $Id: keyboard.s 1.4 1999/10/07 22:49:16 jah Exp jah $
  5. ;  :History.    30.08.97 extracted from some slave sources
  6. ;        17.11.97 _keyexit2 added
  7. ;        23.12.98 _key_help added
  8. ;        07.10.99 some cosmetic changes, documentation improved
  9. ;  :Requires.    _keydebug    byte variable containing rawkey code
  10. ;        _keyexit    byte variable containing rawkey code
  11. ;  :Optional.    _keyexit2    byte variable containing rawkey code
  12. ;        _key_help    function to execute on help pressed
  13. ;        _debug        function to quit with debug
  14. ;        _exit        function to quit
  15. ;  :Copyright.    Public Domain
  16. ;  :Language.    68000 Assembler
  17. ;  :Translator.    Barfly 2.9
  18. ;  :To Do.
  19. ;---------------------------------------------------------------------------*
  20. ; this routine setups a keyboard handler, realizing quit and quit-with-debug
  21. ; feature by pressing the appropriate key. the following variables must be
  22. ; defined:
  23. ;    _keyexit
  24. ;    _keydebug
  25. ; the labels should refer to the Slave structure, so user definable quit- and
  26. ; debug-key will be supported
  27. ; the optional variable:
  28. ;    _keyexit2
  29. ; can be used to specify a second quit-key, if a quit by two different keys
  30. ; should be supported
  31. ; the optional function:
  32. ;    _key_help
  33. ; will be called when the 'help' key is pressed, the fuction must return via
  34. ; 'rts' and must not change any registers
  35. ;
  36. ; IN:    -
  37. ; OUT:    -
  38.  
  39. _SetupKeyboard
  40.     ;set the interrupt vector
  41.         pea    (.int,pc)
  42.         move.l    (a7)+,($68)
  43.     ;allow interrupts from the keyboard
  44.         move.b    #CIAICRF_SETCLR|CIAICRF_SP,(ciaicr+_ciaa)
  45.     ;clear all ciaa-interrupts
  46.         tst.b    (ciaicr+_ciaa)
  47.     ;set input mode
  48.         and.b    #~(CIACRAF_SPMODE),(ciacra+_ciaa)
  49.     ;clear ports interrupt
  50.         move.w    #INTF_PORTS,(intreq+_custom)
  51.     ;allow ports interrupt
  52.         move.w    #INTF_SETCLR|INTF_INTEN|INTF_PORTS,(intena+_custom)
  53.         rts
  54.  
  55. .int        movem.l    d0-d1/a1,-(a7)
  56.         lea    (_ciaa),a1
  57.     ;check if keyboard has caused interrupt
  58.         btst    #CIAICRB_SP,(ciaicr,a1)
  59.         beq    .end
  60.     ;read keycode
  61.         move.b    (ciasdr,a1),d0
  62.     ;set output to low and output mode (handshake)
  63.         clr.b    (ciasdr,a1)
  64.         or.b    #CIACRAF_SPMODE,(ciacra,a1)
  65.     ;calculate rawkeycode
  66.         not.b    d0
  67.         ror.b    #1,d0
  68.  
  69.         cmp.b    (_keydebug),d0
  70.         bne    .1
  71.         movem.l    (a7)+,d0-d1/a1
  72.         move.w    (a7),(6,a7)            ;sr
  73.         move.l    (2,a7),(a7)            ;pc
  74.         clr.w    (4,a7)                ;ext.l sr
  75.     IFD _debug
  76.         bra    _debug
  77.     ELSE
  78.         bra    .debug
  79.     ENDC
  80.  
  81. .1        cmp.b    (_keyexit),d0
  82.     IFD _exit
  83.         beq    _exit
  84.     ELSE
  85.         beq    .exit
  86.     ENDC
  87.  
  88.     IFD _keyexit2
  89.         cmp.b    (_keyexit2),d0
  90.     IFD _exit
  91.         beq    _exit
  92.     ELSE
  93.         beq    .exit
  94.     ENDC
  95.     ENDC
  96.  
  97.     IFD _key_help
  98.         cmp.b    #$5f,d0
  99.         bne    .2
  100.         bsr    _key_help
  101. .2
  102.     ENDC
  103.  
  104.     ;better would be to use the cia-timer to wait, but we arn't know if
  105.     ;they are otherwise used, so using the rasterbeam
  106.     ;required minimum waiting is 75 µs, one rasterline is 63.5 µs
  107.     ;a loop of 3 results in min=127µs max=190.5µs
  108.         moveq    #3-1,d1
  109. .wait1        move.b    (_custom+vhposr),d0
  110. .wait2        cmp.b    (_custom+vhposr),d0
  111.         beq    .wait2
  112.         dbf    d1,.wait1
  113.  
  114.     ;set input mode
  115.         and.b    #~(CIACRAF_SPMODE),(ciacra,a1)
  116. .end        move.w    #INTF_PORTS,(intreq+_custom)
  117.         movem.l    (a7)+,d0-d1/a1
  118.         rte
  119.  
  120.     IFND _exit
  121. .debug        pea    TDREASON_DEBUG.w
  122. .quit        move.l    (_resload),-(a7)
  123.         addq.l    #resload_Abort,(a7)
  124.         rts
  125. .exit        pea    TDREASON_OK.w
  126.         bra    .quit
  127.     ENDC
  128.  
  129.